#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef struct TNode
{
    char Data;
    struct TNode * lchild;
    struct TNode * rchild;
}* PTree,Tree;
void CreateTree(PTree *root,char *s1,char *s2,int len);
void PostorderTraverse(PTree T);
int main()
{
    //freopen("in.txt","r",stdin);
    char s1[10000];
    char s2[10000];
    cin >> s2;
    cin >> s1;
    PTree p = NULL;
    int len = strlen(s2);
    CreateTree(&p,s1,s2,len);
    PostorderTraverse(p);
}

void CreateTree(PTree *root,char *s1,char *s2,int len)
{
    char *temp;
    int k;
    if(len <= 0)
    {
        *root = NULL;
        return;
    }
    if(len > 0)
    {
        for(temp = s2; temp < s2 + len;temp++)
        {
            if(*temp == *s1)
            {
                k = temp - s2;
                *root = (PTree)malloc(sizeof(Tree));
                (*root)->Data = *temp;
                break;
            }
        }
        CreateTree(&((*root)->lchild),s1+1,s2,k);
        CreateTree(&((*root)->rchild),s1+1+k,temp+1,len-k-1);
    }
}

void PostorderTraverse(PTree T)
{
    if(T!=NULL)
    {
        PostorderTraverse(T->lchild);
        PostorderTraverse(T->rchild);
        printf("%c",T->Data);
    }
}